<?php
declare(strict_types=1);
namespace cms\exam\listener;

use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Utils\Arr;
use Hyperf\Validation\Event\ValidatorFactoryResolved;

/**
 * Class ValidatorFactoryResolvedListener
 * @package cms\exam\listener
 * @Listener()
 */
class ValidatorFactoryResolvedListener implements ListenerInterface
{

    public function listen(): array
    {
        return [
            ValidatorFactoryResolved::class,
        ];
    }

    public function process(object $event)
    {
        $validatorFactory = $event->validatorFactory;
        $validatorFactory->extend('topic', function ($attribute, $value, $parameters, $validator) {
            $data = $validator->getData();
            // 取得题目类型
            $type = Arr::get($data, 'type', '');
            if (Arr::has($value, 'subject')) {
                return false;
            }
            if ($type == 'select-single') {

            }
            return false;
        });
    }
}